package me.jzn.alib.beans;

/**下个版本将要删除，
 *  @see me.jzn.core.beans.Acc
 */
@Deprecated
public final class Acc {
    public final AccType type;
    public final String value;

    public Acc(String value) {
        this.type = AccType.name;
        this.value = value;
    }

    public Acc(AccType type, String value) {
        this.type = type;
        this.value = value;
    }

    public static Acc fromString(String str) {
        int splitIdx = str.indexOf(':');
        if (splitIdx < 0) {
            return new Acc(str);
        }
        AccType type = AccType.valueOf(str.substring(0, splitIdx));
        String value = str.substring(splitIdx + 1);
        return new Acc(type, value);
    }

    public String asString() {
        return type + ":" + value;
    }

    @Override
    public String toString() {
        return type + ":" + value;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj != null && obj instanceof Acc) {
            Acc that = (Acc) obj;
            return this.type.equals(that.type) && this.value.equals(that.value);
        }
        return false;
    }

    public static enum AccType {
        uid, name, phone, email
    }
}
